//
//  LGHospitalPlanHomeCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/5/29.
//

#import "LGHospitalPlanHomeCell.h"

@interface LGHospitalPlanHomeCell()

/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UIButton *titleBtn;
/**   */
@property (nonatomic , strong)UILabel *statusLabel;
/**   */
@property (nonatomic , strong)UIImageView *headPic;
/**   */
@property (nonatomic , strong)UILabel *nameLabel;
/**   */
@property (nonatomic , strong)UILabel *ageLabel;
/**   */
@property (nonatomic , strong)UIImageView *iconView;
/**   */
@property (nonatomic , strong)UILabel *dateLabel;
/**  忽略 */
@property (nonatomic , strong)UIButton *ignoreBtn;
/**  通知 */
@property (nonatomic , strong)UIButton *notificationBtn;

@end

@implementation LGHospitalPlanHomeCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    [self.titleBtn setTitle:LGNSString(dataDic[@"type_name"]) forState:UIControlStateNormal];
    UIImage *placeHolder = [LGNSString(dataDic[@"gender"]) isEqualToString:@"男"]?defaultPatientMan:defaultPatientWomen;
    [self.headPic sd_setImageWithURL:[NSURL URLWithString:dataDic[@""]] placeholderImage:placeHolder];
    self.nameLabel.text = LGNSString(dataDic[@"realname"]);
    self.ageLabel.text = [NSString stringWithFormat:@"%@ %@岁",dataDic[@"gender"],dataDic[@"age"]];
    self.statusLabel.text = LGNSString(dataDic[@"state_name"]);
    CGFloat baseHeight = viewPix(182);
    //0：未安排 、 1：已安排 、 2：已逾期 、3：已忽略
    self.notificationBtn.hidden = NO;
    if([dataDic[@"state"] integerValue]==0){
        //未安排
        self.ignoreBtn.hidden = NO;
        [self.notificationBtn setTitle:@"通知入院" forState:UIControlStateNormal];
        self.statusLabel.textColor = [UIColor colorWithString:@"#3291FF"];
        self.dateLabel.text = [NSString stringWithFormat:@"计划入院日期：%@ ~ %@",dataDic[@"plan_date_start"],dataDic[@"plan_date_end"]];
    }else if ([dataDic[@"state"] integerValue]==1){
        //已安排
        self.ignoreBtn.hidden = YES;
        [self.notificationBtn setTitle:@"再次通知" forState:UIControlStateNormal];
        self.statusLabel.textColor = [UIColor colorWithString:@"#999999"];
        self.dateLabel.text = [NSString stringWithFormat:@"安排入院日期：%@ ",dataDic[@"appointment_date"]];
        
    }else if ([dataDic[@"state"] integerValue]==2){
        //已逾期
        self.ignoreBtn.hidden = NO;
        [self.notificationBtn setTitle:@"通知入院" forState:UIControlStateNormal];
        self.statusLabel.textColor = [UIColor colorWithString:@"#EB5757"];
        self.dateLabel.text = [NSString stringWithFormat:@"计划入院日期：%@ ~ %@",dataDic[@"plan_date_start"],dataDic[@"plan_date_end"]];
    }else{
        //已忽略
        self.ignoreBtn.hidden = YES;
        self.notificationBtn.hidden = YES;
        self.statusLabel.textColor = [UIColor colorWithString:@"#999999"];
        self.dateLabel.text = [NSString stringWithFormat:@"计划入院日期：%@ ~ %@",dataDic[@"plan_date_start"],dataDic[@"plan_date_end"]];
        baseHeight = viewPix(145);
    }
    [self.baseView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@(baseHeight));
    }];
}

//忽略
-(void)ignoreBtnAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(ignoreButtonAction:)]){
        [self.delegate ignoreButtonAction:self.dataDic];
    }
}

//通知入院
-(void)notificationBtnAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(admissionNoticeAction:)]){
        [self.delegate admissionNoticeAction:self.dataDic];
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.contentView.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.titleBtn];
    [self.baseView addSubview:self.statusLabel];
    [self.baseView addSubview:self.headPic];
    [self.baseView addSubview:self.nameLabel];
    [self.baseView addSubview:self.ageLabel];
    [self.baseView addSubview:self.iconView];
    [self.baseView addSubview:self.dateLabel];
    [self.baseView addSubview:self.ignoreBtn];
    [self.baseView addSubview:self.notificationBtn];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(viewPix(8));
        make.left.equalTo(self.contentView).offset(viewPix(16));
        make.right.equalTo(self.contentView).offset(-viewPix(16));
        make.bottom.equalTo(self.contentView).offset(-viewPix(8));
        make.height.equalTo(@(viewPix(182)));
    }];
    [self.titleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.baseView).offset(viewPix(16));
        make.left.equalTo(self.baseView);
        make.width.equalTo(@(viewPix(84)));
        make.height.equalTo(@(viewPix(27)));
    }];
    [self.statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.centerY.equalTo(self.titleBtn);
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headPic.mas_right).offset(viewPix(8));
        make.centerY.equalTo(self.headPic);
    }];
    [self.ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right).offset(viewPix(4));
        make.centerY.equalTo(self.headPic);
    }];
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(viewPix(4));
        make.centerY.equalTo(self.iconView);
    }];
    [self.ignoreBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.notificationBtn.mas_left).offset(-viewPix(12));
        make.centerY.equalTo(self.notificationBtn);
        make.width.equalTo(@(80));
        make.height.equalTo(@(33));
    }];
    [self.notificationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.baseView).offset(-viewPix(12));
        make.top.equalTo(self.iconView.mas_bottom).offset(viewPix(10));
        make.width.equalTo(@(100));
        make.height.equalTo(@(33));
    }];
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.1 radius:15];
        _baseView.backgroundColor = [UIColor whiteColor];
        _baseView.cornerRidus = 15;
    }
    return _baseView;
}

-(UIButton *)titleBtn{
    if(!_titleBtn){
        _titleBtn = [UIButton buttonWithTitle:@"" titleFont:LGFontWeight(15, UIFontWeightMedium) textColor:@"#1F6CC6" imageName:@""];
        _titleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _titleBtn.titleEdgeInsets = UIEdgeInsetsMake(0, viewPix(8), 0, 0);
        [_titleBtn setBackgroundImage:[UIImage imageNamed:@"就诊检查-蓝色"] forState:UIControlStateNormal];
    }
    return _titleBtn;
}

-(UILabel *)statusLabel{
    if(!_statusLabel){
        _statusLabel = [UILabel lableWithText:@"已安排" colorString:@"#999999" textFont:LGFontWeight(14, UIFontWeightMedium) textAlignment:NSTextAlignmentRight lines:1];
    }
    return _statusLabel;
}

-(UIImageView *)headPic{
    if(!_headPic){
        _headPic = [[UIImageView alloc]initWithFrame:CGRectMake(viewPix(12), viewPix(60), viewPix(32), viewPix(32))];
        _headPic.backgroundColor = [UIColor colorWithString:@"#F9F9F9"];
        _headPic.cornerRidus = 4;
    }
    return _headPic;
}

-(UILabel *)nameLabel{
    if(!_nameLabel){
        _nameLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _nameLabel;
}

-(UILabel *)ageLabel{
    if(!_ageLabel){
        _ageLabel = [UILabel lableWithText:@"" colorString:@"#999999" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _ageLabel;
}

-(UIImageView *)iconView{
    if(!_iconView){
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"我的订单-订单时间"]];
        _iconView.frame = CGRectMake(viewPix(12), kMaxY(self.headPic.frame)+viewPix(16), viewPix(16), viewPix(16));
    }
    return _iconView;
}

-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"计划入院日期：" colorString:@"#666666" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _dateLabel;
}

-(UIButton *)ignoreBtn{
    if(!_ignoreBtn){
        _ignoreBtn = [UIButton buttonWithTitle:@"忽略" titleFont:LGFontWeight(15, UIFontWeightMedium) textColor:@"#3291FF" imageName:@""];
        _ignoreBtn.layer.borderColor = [UIColor colorWithString:@"#3291FF"].CGColor;
        _ignoreBtn.layer.borderWidth = 1;
        _ignoreBtn.cornerRidus = 16;
        [_ignoreBtn addTarget:self action:@selector(ignoreBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _ignoreBtn;
}

-(UIButton *)notificationBtn{
    if(!_notificationBtn){
        _notificationBtn = [UIButton buttonWithTitle:@"通知入院" titleFont:LGFontWeight(15, UIFontWeightMedium) textColor:@"#FFFFFF" imageName:@""];
        _notificationBtn.backgroundColor = [UIColor colorWithString:@"#3291FF"];
        _notificationBtn.cornerRidus = 16;
        [_notificationBtn addTarget:self action:@selector(notificationBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _notificationBtn;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
